﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Bookkeeping.Core.Entities;
using Bookkeeping.Mvc.Models.Rendering;

namespace Bookkeeping.Mvc.Models.Budget
{
    public class PostListViewModel
    {
        public PostListViewModel(IEnumerable<Post> posts, string title, double totalAmount)
        {
            Posts = posts.Select(p => new PostViewModel(p)).ToList();
            Title = title;
            TotalAmount = totalAmount;
        }

        public string Title { get; private set; }
        public IEnumerable<PostViewModel> Posts { get; private set; }
        public double TotalAmount { get; private set; }

        public string TotalAmountString
        {
            get
            {
                return TotalAmount.ToString("C");
            }
        }

        public string TotalAmountCssClass
        {
            get
            {
                return Css.GetAmountClass(TotalAmount);
            }
        }

        public void SelectPostById(int selectedId)
        {
            var postToSelect = Posts.SingleOrDefault(p => p.Id == selectedId);

            if (postToSelect != null)
                postToSelect.IsSelected = true;
        }
    }
}
